(() => {

    'use strict';
    goog.provide('Blockly.Arduino.ruilong');
    goog.require('Blockly.Arduino');

    goog.require('path');

    const mediaDirPath = path.join(document.currentScript.src, '../../media/');

    Blockly.Msg['RUILONG_HUE'] = 120;
 //电阻侦测传感器
    Blockly.Blocks.ruilong_resistor_scratch = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("电阻侦测传感器");
            this.appendValueInput("PIN", Number)
                .appendField(Blockly.Msg.MIXLY_PIN)
                .setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //温度传感器（LM35）
    Blockly.Blocks.ruilong_temp = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("")
                .appendField("温度传感器（LM35）");
            this.appendValueInput("PIN", Number)
                .appendField(Blockly.Msg.MIXLY_PIN)
                .setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //热敏传感器
    Blockly.Blocks.ruilong_temp2 = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("")
                .appendField("热敏传感器");
            this.appendValueInput("PIN", Number)
                .appendField(Blockly.Msg.MIXLY_PIN)
                .setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //声音传感器
    Blockly.Blocks.ruilong_sound = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("声音传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //土壤湿度传感器
    Blockly.Blocks.ruilong_moisture = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("土壤湿度传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //水滴传感器
    Blockly.Blocks.ruilong_steam = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("水滴传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //寻迹传感器
    Blockly.Blocks.ruilong_linefinder = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("寻迹传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };

    //旋钮传感器
    Blockly.Blocks.ruilong_knob = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("旋钮传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //滑杆传感器
    Blockly.Blocks.ruilong_slider = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("滑杆传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //摇杆传感器
    Blockly.Blocks.ruilong_joystick_x = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("摇杆传感器(X)");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //摇杆传感器
    Blockly.Blocks.ruilong_joystick_y = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("摇杆传感器(Y)");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //光线传感器
    Blockly.Blocks.ruilong_light = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("光线传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //气体传感器（MQ系列）
    Blockly.Blocks.ruilong_mqx = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("气体传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //5按键传感器
    Blockly.Blocks.ruilong_5button = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("5按键传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('数值返回1、2、3、4、5，默认为0');
        }
    };
    //火焰传感器
    Blockly.Blocks.ruilong_fire = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("火焰传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //mini摇杆传感器
    Blockly.Blocks.ruilong_minijoystick = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("mini摇杆传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('数值返回1、2、3、4、5，默认为0');
        }
    };

    //浊度传感器
    Blockly.Blocks.ruilong_turbidity = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("浊度传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };

    //ADS1015模拟数字转换模块-获取数据
    var ruilong_ADS1015_setGain = [
        ["±6.144V 3mv/bit 0.1875mV/bit（默认）", "GAIN_TWOTHIRDS"],
        ["±4.096V 2mv/bit 0.125mV/bit", "GAIN_ONE"],
        ["±2.048V 1mv/bit 0.0625mV/bit", "GAIN_TWO"],
        ["±1.024V 0.5mv/bit 0.03125mV/bit", "GAIN_FOUR"],
        ["±0.512V 0.25mv/bit 0.015625mV/bit", "GAIN_EIGHT"],
        ["±0.256V 0.125mv/bit 0.0078125mV/bit", "GAIN_SIXTEEN"],
    ];

    //ADS1015模拟数字转换模块-增益设置
    Blockly.Blocks.ruilong_ADS1015_setGain = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField(Blockly.Msg.MIXLY_SETTING).appendField(new Blockly.FieldDropdown([["ADS1015", "ADS1015"], ["ADS1115", "ADS1115"]]), "ADS1X15").appendField("采样范围和精度");
            this.appendDummyInput("").setAlign(Blockly.ALIGN_RIGHT).appendField(new Blockly.FieldDropdown(ruilong_ADS1015_setGain), "ADS1015_setGain");
            this.setInputsInline(true);
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
            this.setTooltip();
        }
    };
    //ADS1015模拟数字转换模块 数值获取
    Blockly.Blocks.ruilong_ADS1015 = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField(new Blockly.FieldDropdown([["ADS1015", "ADS1015"], ["ADS1115", "ADS1115"]]), "ADS1X15").appendField("模数转换模块");
            this.appendDummyInput("").appendField(new Blockly.FieldDropdown([["AIN0", "ads.readADC_SingleEnded(0)"], ["AIN1", "ads.readADC_SingleEnded(1)"], ["AIN2", "ads.readADC_SingleEnded(2)"], ["AIN3", "ads.readADC_SingleEnded(3)"]]), "ADS1015_AIN");
            this.setInputsInline(true);
            this.setOutput(true);

        }
    };

    //PCF8591T模拟数字转换模块 数值获取
    Blockly.Blocks.ruilong_PCF8591T = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("PCF8591T模数转换模块");
            this.appendDummyInput("").appendField(new Blockly.FieldDropdown([["AIN0", "pcf8591.analogRead(AIN0)"], ["AIN1", "pcf8591.analogRead(AIN1)"], ["AIN2", "pcf8591.analogRead(AIN2)"], ["AIN3", "pcf8591.analogRead(AIN3)"]]), "PCF8591T_AIN");
            this.setInputsInline(true);
            this.setOutput(true);
        }
    };

})();